package models

import "time"
import "gorm.io/gorm"
import "go_part/utils"
//import "fmt"

type DeviceType struct{
	gorm.Model
	Name string
	DeviceTypeID string
	CompanyID string
	Phone string 
	Email string 
	LoginTime time.Time
	isLogout bool
	DeviceInfo string
 }

func (table *DeviceType) TableName() string {

	return "device_type_basic"
}

func GetDeviceTypeList() []*DeviceType { 
	data := make([]*DeviceType,10)
	utils.DB.Find(&data)
	// for _,v : = range data {
	// 	fmt.Println(v)
	// }
	return data
}

func FindDeviceTypeByName(name string) DeviceType {
	user := DeviceType{}
	utils.DB.Where("name = ?",name).Find(&user)
	return user
}

func FindDeviceTypeByID(id uint) DeviceType {
	user := DeviceType{}
	utils.DB.Where("id = ?",id).First(&user)
	return user
}

func CreateDeviceType(user DeviceType) *gorm.DB {
	
	return utils.DB.Create(&user)
}

func DeleteDeviceType(user DeviceType) *gorm.DB {
	
	return utils.DB.Delete(&user)
}

func UpdateDeviceType(user DeviceType) *gorm.DB {
	
	return utils.DB.Model(&user).Updates(DeviceType{Name: user.Name, DeviceInfo: user.DeviceInfo})
}